﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PublicCommon;
using T_Rbac.Read.APi.Application.Command.Dapartments;
using T_Rbac_Demain;

namespace T_Rbac.Read.APi.Controllers
{
    /// <summary>
    /// 部门
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DapartmentReadController : ControllerBase
    {
        private readonly IMediator mediator;

        public DapartmentReadController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 反填数据
        /// </summary>
        /// <param name="dapartmentsFindbyidCommand"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Dapartment> GetDapartmentbyid([FromQuery]DapartmentsFindbyidCommand dapartmentsFindbyidCommand)
        {
            return await mediator.Send(dapartmentsFindbyidCommand);
        }
        /// <summary>
        /// 获取下拉列表
        /// </summary>
        /// <param name="dapartmentsReadAllCommand"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IQueryable<Dapartment>>GetDapartmentValues([FromQuery]DapartmentsReadAllCommand dapartmentsReadAllCommand)
        {
            return await mediator.Send(dapartmentsReadAllCommand);  
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="departmentSearchCommand"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageResult<Dapartment>> GetDapartmentPageResult([FromQuery]DepartmentSearchCommand departmentSearchCommand)
        {
            return await mediator.Send(departmentSearchCommand);
        }
        /// <summary>
        /// 查询pid下的部门数据
        /// </summary>
        /// <param name="dapartmentSearchByDidCommand"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IQueryable<Dapartment>> GetDapartmentBysearchPid([FromQuery]DapartmentSearchByDidCommand dapartmentSearchByDidCommand)
        {
            return await mediator.Send(dapartmentSearchByDidCommand);
        }
        /// <summary>
        /// 树型部门
        /// </summary>
        /// <param name="dapartmentTreeSearchBypidCommand"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<PublicTree<Dapartment>>> GetDapartmentBypid([FromQuery]DapartmentTreeSearchBypidCommand dapartmentTreeSearchBypidCommand)
        {
            return await mediator.Send(dapartmentTreeSearchBypidCommand);
        }
    }
}
